//
//  StellCalculatorViewModel.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/22.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "StellCalculatorViewModel.h"
#import "StellCaiculatorCollectionViewCell.h"

@interface StellCalculatorViewModel ()<UICollectionViewDelegate,UICollectionViewDataSource,YLJCollectionViewFlowLayoutDelegate>{
    NSArray * listDataTitleArr;
    NSArray * listDataImageArr;
}
@end

@implementation StellCalculatorViewModel

-(instancetype)initWithViewToViewCollectionView:(UICollectionView *)collectionView theFlowLayout:(YLJCollectionViewFlowLayout *)flowlayout theSuperView:(UIView *)superView{
    if (self = [super initWithViewToViewCollectionView:collectionView theFlowLayout:flowlayout theSuperView:superView]) {
        listDataTitleArr = @[@"钢板",@"螺纹钢",@"圆钢盘条",@"H型钢",@"等边角钢",@"不等边角钢",@"槽钢",@"工字钢",@"钢管",@"螺旋管",@"扁钢",@"六角钢",@"八角钢",@"花纹钢板"];
        listDataImageArr = @[@"icon_gangban",
                             @"icon_luowengang",
                             @"icon_luogangpantiao",
                             @"icon_hxinggang",
                             @"icon_dengbianjiaogang",
                             @"icon_budengbianjiaogang",
                             @"icon_caogang",
                             @"icon_gongzigang",
                             @"icon_gangguan",
                             @"icon_luoxuanguan",
                             @"icon_biangang",
                             @"icon_liujiaogang",
                             @"icon_bajiaogang",
                             @"icon_huawengangban"];
        collectionView.y = collectionView.y+ kHeightProportion_In_iPhoneTriploid(10);
        collectionView.height = collectionView.height - kHeightProportion_In_iPhoneTriploid(10);
        flowlayout.delegate = self;
        collectionView.delegate = self;
        collectionView.dataSource = self;
        [collectionView registerClass:[StellCaiculatorCollectionViewCell class] forCellWithReuseIdentifier:@"StellCaiculatorCollectionViewCell"];
        [superView addSubview:collectionView];
    }
    return self;
}

#pragma mark --- UICollectionViewDelegate,UICollectionViewDataSource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return listDataTitleArr.count;
}

- (ZLLayoutType)collectionView:(UICollectionView *)collectionView layout:(YLJCollectionViewFlowLayout *)collectionViewLayout typeOfLayout:(NSInteger)section{
    return ClosedLayout;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    StellCaiculatorCollectionViewCell * cell = [StellCaiculatorCollectionViewCell cellWithCollectionView:collectionView forIndexPath:indexPath];
    [cell theStellName:listDataTitleArr[indexPath.row] theStellImage:listDataImageArr[indexPath.row]];
    return cell;
}

//如果是百分比布局必须实现该代理，设置每个item的百分比，如果没实现默认比例为1
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(YLJCollectionViewFlowLayout*)collectionViewLayout percentOfRow:(NSIndexPath*)indexPath{
    return 1;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(kWidthProportion_In_iPhoneTriploid(101), kHeightProportion_In_iPhoneTriploid(101));
}

//如果是绝对定位布局必须是否该代理，设置每个item的frame
- (CGRect)collectionView:(UICollectionView *)collectionView layout:(YLJCollectionViewFlowLayout*)collectionViewLayout rectOfItem:(NSIndexPath*)indexPath{
    return CGRectZero;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView layout:(YLJCollectionViewFlowLayout *)collectionViewLayout zIndexOfItem:(NSIndexPath*)indexPath{
    return 0;
}
- (NSInteger)collectionView:(UICollectionView * __nullable)collectionView layout:(YLJCollectionViewFlowLayout* __nullable)collectionViewLayout columnCountOfSection:(NSInteger)section{
    return 3;
}
//行间距(横)
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return kHeightProportion_In_iPhoneTriploid(10);
}
//竖
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return kWidthProportion_In_iPhoneTriploid(10);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(kHeightProportion_In_iPhoneTriploid(18), (KScreenWidth - kWidthProportion_In_iPhoneTriploid(323))/2, kHeightProportion_In_iPhoneTriploid(8), (KScreenWidth - kWidthProportion_In_iPhoneTriploid(323))/2);//top, left, bottom, right;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (self.delegate && [self.delegate respondsToSelector:@selector(stellDidSelectItemAtIndexPath:)]) {
        [self.delegate stellDidSelectItemAtIndexPath:indexPath];
    }
}

@end
